package com.rightrule.rule.constans;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;

/**
 * todo
 */
@Getter
@AllArgsConstructor
public enum FieldSourceEnum {

    BUSINESS_INCOMING(1, "决策输入"),
    DECISION_RETURN(2, "决策输出"),
    RPC_PULL(3, "RPC泛化调用"),
    ODPS_OFFLINE_PULL(4, "自定义SQL"),
    SCRIPT_EXECUTE(5, "脚本");

    Integer code;
    String desc;


    public static Optional<FieldSourceEnum> of(Integer code) {
        if (code == null) {
            return Optional.empty();
        }

        return Arrays.stream(values()).filter(fieldSourceEnum -> Objects.equals(fieldSourceEnum.getCode(), code)).findFirst();
    }

}
